﻿using System;
using System.ComponentModel;
using System.Windows.Forms;
using System.Windows;

namespace BasicFrameworkDemo.Installer
{
    using System.IO;

    [RunInstaller(true)]
    public class CustomeInstaller:System.Configuration.Install.Installer
    {
        public override void Install(System.Collections.IDictionary savedState)
        {
            base.Install(savedState);
            this.ConfigureInstall();
        }

        private void ConfigureInstall()
        {
            string firstName = this.Context.Parameters["FirstName"];
            string lastName = this.Context.Parameters["LastName"];
            this.WriteTxtLog("FirstName:"+firstName+" ,"+"LastName:"+lastName);
        }

        public override void Uninstall(System.Collections.IDictionary savedState)
        {
            base.Uninstall(savedState);
            this.Delete();
        }

        private void Delete()
        {
            this.WriteTxtLog("I'm uninstalled");
        }

        private void WriteTxtLog(string message)
        {
            string fileName = "BasicFrameworkInstallationLog.txt";
            string filePath = "C:\\" + fileName;
            var fst = new FileStream(filePath, FileMode.Append);            
            var swt = new StreamWriter(fst, System.Text.Encoding.GetEncoding("utf-8"));
            swt.WriteLine(message);
            swt.Close();
            fst.Close();
        }
    }
}
